package com.gao.api.gate.quick.proto.server;

import com.gao.api.gate.quick.core.async.ListenableFuture;
import com.gao.api.gate.quick.core.async.ListenableFutureTask;
import com.gao.api.gate.quick.proto.config.HttpServerConfig;
import com.gao.api.gate.quick.proto.http.Request;
import com.gao.api.gate.quick.proto.http.Response;
import com.gao.api.gate.quick.proto.point.Endpoint;
import com.gao.api.gate.quick.proto.point.EndpointHandler;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;

import java.io.IOException;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;

/**
 * <p></p>
 *
 * @author gaoshuangwen
 * @since 2022/01/07 21:44
 */
public class HttpServernEW implements Server{

    private ServerConfig serverConfig;

    private HttpServer httpServer;

    public HttpServernEW(ServerConfig serverConfig) {
        this.serverConfig = serverConfig;
    }

    @Override
    public Server open(ServerConfig config) {
        HttpServer httpServer = new HttpServer(config);
        httpServer.start();
        return new HttpServernEW(config);
    }

    @Override
    public ListenableFuture<Response> send(Request request) {
        ListenableFutureTask<Response> task = new ListenableFutureTask<String>(() -> {
            return next().send(request);
        });
        loop().execute(task);
        return task;
    }

    @Override
    public boolean isRunning() {
        return false;
    }

    @Override
    public EndpointHandler getHandler() {
        return null;
    }

    @Override
    public ExecutorService loop() {
        return null;
    }

    @Override
    public Endpoint<?, ?> next() {
        return null;
    }

    @Override
    public ChannelBindListenableFuture bind() {
        return null;
    }

    @Override
    public void close() throws IOException {

    }
}
